package com.woniuxy.yogaapp.service.imp;

import java.util.List;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.woniuxy.yogaapp.mapper.StudentMapper;
import com.woniuxy.yogaapp.pojo.Student;
import com.woniuxy.yogaapp.pojo.UserRoles;
import com.woniuxy.yogaapp.service.StudentService;
import com.woniuxy.yogaapp.service.UserRolesService;

import lombok.Data;

@Data
@Service
@Transactional
public class StudentServiceImp implements StudentService {
	@Resource
	private StudentMapper studentMapper;
	@Resource
	private UserRolesService userRolesService;

	// 查询所有
	@Override
	public List<Student> findAllStudent() {
		return studentMapper.findAllStudent();

	}

	// 添加学员详细信息
	@Override
	public String addStudentInfo(Student student) {
		String result = "添加失败！";
		int row = studentMapper.addStudentInfo(student);
		// 添加成功 给该用户赋学员角色 以及权限
		UserRoles userRoles = new UserRoles();
		userRoles.setUid(student.getUid());
		userRoles.setRid(2);

		// 添加学员角色
		String result1 = userRolesService.addStudentRoles(userRoles);
		if (result1.contains("失败")) {
			return result1;
		}
		if (row == 1) {
			result = "添加成功！";
		}
		return result;
	}

	// 根据用户id 查询是不是新学员
	@Override
	public Student findStudentByUid(Student student) {

		return studentMapper.findStudentByUid(student);
	}

	// 老用户 修改个人信息
	@Override
	public int updateStudentInfo(Student student) {

		return studentMapper.updateStudentInfo(student);
	}

	// 我的签约教练
	@Override
	public Student findBySidCoach(int sid) {

		return studentMapper.findBySidCoach(sid);
	}

}
